package cn.itcast.controller;

import cn.itcast.DTO.OrderDTO;
import cn.itcast.entity.Order;
import cn.itcast.entity.Result;
import cn.itcast.entity.Room;
import cn.itcast.VO.OrderDayVO;
import cn.itcast.VO.OrderFlowVO;
import cn.itcast.VO.OrderUserVO;
import cn.itcast.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @PostMapping("/add")
    public Result addOrder(@RequestBody OrderDTO orderDTO) {
        log.info("addOrder Order:{}", orderDTO);
        orderService.addOrder(orderDTO);
        return Result.success();
    }

    @GetMapping("/{roomId}")
    public Result<OrderDayVO> getOrderDay(@PathVariable Long roomId) {
        log.info("getOrderCount roomId:{}", roomId);
        OrderDayVO orderDay = orderService.getOrderDay(roomId);
        return Result.success(orderDay);
    }

    @GetMapping("/userId/{id}")
    public Result<OrderUserVO> getOrderUserId(@PathVariable Integer id) {
        log.info("userId:{}", id);
        OrderUserVO orderUserVO = orderService.getOrderUserId(id);
        return Result.success(orderUserVO);
    }

    @PostMapping("/room")
    public Result<Order> getOrderById(@RequestBody Room room) {
        log.info("roomId:{}", room);
        Order order = orderService.getOrderByRoomId(room.getId());
        return Result.success(order);
    }

    //修改订单
    @PutMapping("/update")
    public Result updateOrder(@RequestBody Order order) {
        log.info("updateOrder order:{}", order);
        orderService.updateOrder(order);
        return Result.success();
    }

    //每日流量
    @GetMapping("/flow")
    public Result<OrderFlowVO> flow(){
        return Result.success(orderService.flow());
    }
}
